<?php

namespace App\Http\Requests\Api;

class CustomerInfoRequest extends FormRequest
{
    public function rules()
    {
        switch ($this->method()) {
            case 'POST':
                $arr = [
                    'name' => 'required|string',
                    'phone' => 'required|phone:CN,mobile',
                    'vehicle_id' => 'required|integer',
                    'province' => 'required|string',
                    'city' => 'required|string',
                    'dealer_id' => 'required|integer|exists:dealers,id',
                    'referee_id' => 'integer|exists:referees,user_id',
                ];
                return $arr;
                break;
            case 'PUT':
            case 'PATCH':
                $arr = [
                    'province' => 'required|string',
                    'city' => 'required|string',
                    'dealer_id' => 'required|integer|exists:dealers,id',
                ];
                return $arr;
                break;
        }
    }

    public function attributes()
    {
        return [
            'name' => '姓名',
            'phone' => '手机号',
            'vehicle_id' => '车型ID',
            'province' => '省份',
            'city' => '城市',
            'store' => '店铺名',
            'store_id' => '店铺ID',
        ];
    }

    public function messages()
    {
        return [
            'phone.phone' => '手机号不存在',
        ];
    }
}
